package com.springboot.springautowired.javaDesignModel.decoratorModel;

/**
 * 装饰者模式----和代理模式很像
 *  三要素
 *      抽象构件
 *      具体构件
 *      具体装饰类
 *
 * @author mac
 * @date 2021/9/17 11:36 上午
 */
public class DecorateDesignModel {
    public static void main(String[] args) {
        DecoratorOfOperation.decorator();
    }
}

/**
 * 抽象构件
 */
interface ComponentClass{
    public void movie();
}

/**
 * 具体装饰者
 */
class ConcreteDecorator implements ComponentClass{
    private ConcreteComponent concreteComponent;

    public ConcreteDecorator(ConcreteComponent concreteComponent) {
        this.concreteComponent = concreteComponent;
    }

    @Override
    public void movie() {
        System.out.println("我是装饰者");
        concreteComponent.movie();
    }
}

/**
 * 具体构件
 */
class ConcreteComponent implements ComponentClass{
    @Override
    public void movie() {
        System.out.println("我是具体构件");
    }
}

class DecoratorOfOperation{
    public static void decorator(){
        ConcreteComponent concreteComponent = new ConcreteComponent();
        ConcreteDecorator concreteDecorator = new ConcreteDecorator(concreteComponent);
        concreteDecorator.movie();
    }
}